<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"
%><%@ attribute name="totalSize" type="java.lang.Integer" required="true"
%><%@ attribute name="search" type="com.company.project.web.util.SearchParameters" required="true"
%><%@ attribute name="url" type="java.lang.String"
%><%
	int pageSize = search.getPageSize();
	int pageNumber = search.getPageNumber();
	
	int totalPages = ((totalSize - 1) / pageSize) + 1;

	boolean hasFirstPage 	= false;
	boolean hasPreviousPage = false;
	boolean hasNextPage 	= false;
	boolean hasLastPage 	= false;

	int previousPage 	= 0;
	int nextPage 		= 0;
	int lastPage 		= totalPages;

	if (pageNumber > 1) {
		hasFirstPage = true;
		hasPreviousPage = true;
		previousPage = pageNumber - 1;
	}
	if (pageNumber < totalPages) {
		hasNextPage = true;
		hasLastPage = true;
		nextPage = pageNumber + 1;
	}
%>
<c:set var="operator" value="?"/>
<c:url var="computedUrl" value="${url}">
	<c:forEach items="${param}" var="par">
		<c:choose>
			<c:when test="${par.key == 'decorator'}"/>
			<c:when test="${par.key == 'pageNumber'}"/>
			<c:otherwise>
				<c:param name="${par.key}" value="${par.value}"/>
				<c:set var="operator" value="&amp;"/>
			</c:otherwise>
		</c:choose>
	</c:forEach>
</c:url>
	
<form action="${computedUrl}">
	<c:forEach items="${param}" var="par">
		<c:choose>
			<c:when test="${par.key == 'decorator'}"/>
			<c:when test="${par.key == 'pageNumber'}"/>
			<c:otherwise>
				<input type="hidden" name="${par.key}" value="<c:out value="${par.value}"/>"/>
			</c:otherwise>
		</c:choose>
	</c:forEach>
	<p class="navigation">
		<%if (hasFirstPage) { %>
			<a id="pageFirst" class="ajaxLink" href="${computedUrl}${operator}pageNumber=0"><fmt:message key="navigation.first"/></a>
		<% } else { %>
			<span id="pageFirst"><fmt:message key="navigation.first"/></span>
		<% } %>
		
		<%if (hasPreviousPage) { %>
			<a id="pagePrev" class="ajaxLink" href="${computedUrl}${operator}pageNumber=<%= previousPage %>"><fmt:message key="navigation.previous"/></a>
		<% } else { %>
			<span id="pagePrev"><fmt:message key="navigation.previous"/></span>
		<% } %>
	
		<input name="pageNumber" type="text" value="<%= pageNumber %> / <%= totalPages %>" onClick="this.value='';this.select();"/>
	
		<%if (hasNextPage) { %>
			<a id="pageNext" class="ajaxLink" href="${computedUrl}${operator}pageNumber=<%= nextPage %>"><fmt:message key="navigation.next"/></a>
		<% } else { %>
			<span id="pageNext"><fmt:message key="navigation.next"/></span>
		<% } %>
		
		<%if (hasLastPage) { %>
			<a id="pageLast" class="ajaxLink" href="${computedUrl}${operator}pageNumber=<%= lastPage %>"><fmt:message key="navigation.last"/></a>
		<% } else { %>
			<span id="pageLast"><fmt:message key="navigation.last"/></span>
		<% } %>
	</p> 
</form>